package club.babyf.springai.dao;

import club.babyf.springai.entity.User;
import club.babyf.springai.entity.UserFetcher;
import club.babyf.springai.entity.UserTable;
import org.babyfish.jimmer.spring.repository.JRepository;

import java.util.Optional;

public interface UserRepository extends JRepository<User, String> {

    UserTable t = UserTable.$;

    UserFetcher FETCHER = UserFetcher.$.allScalarFields();

    default Optional<User> findByPhone(String phone) {
        return sql().createQuery(t)
                .where(t.phone().eq(phone))
                .select(t)
                .fetchOptional();
    }

}
